const app = getApp()
const connector = require('../../../utils/connector.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar_Height: wx.getSystemInfoSync().statusBarHeight + 45,
    list:[],
    limit:1,

  },
  //积分流水
  integral(e){
    wx.navigateTo({
      url: "./integral/integral",
    })
  },
  //提现
  distributionTopTBtn(e){
    // console.log(e)
    // console.log(e.currentTarget.dataset.withdraw)
    let that = this
    let limit = that.data.limit
    if(e.currentTarget.dataset.withdraw/limit < 1){
      connector.showToasts("你的积分小于"+limit+"，不能使用")
    }else{
      wx.navigateTo({
        url: "./withdraw/withdraw?money=" + e.currentTarget.dataset.withdraw,
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    userMoneyRank(this)
    userMoneyLimit(this)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    userFund(this)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {
    var that = this
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  }
})
//用户资金信息
function userFund(that){
  connector.getFunc(connector.connector().userFund, "", "get", app.tokens, function (res) {
    // console.log(res)
    if (res.statusCode == 200) {
      // console.log(res.data.result)
      that.setData({
        money:res.data.result
      })
    }else{
      connector.showToasts(res.errMsg)
    }
  }, function (res) {
    connector.showToasts("内部错误")
    // wx.showToast({
    //   title: "内部错误",
    //   icon: 'none',
    //   duration: 1000
    // })
  })
}
//用户流动资金信息
function userMoneyRank(that){
  connector.getFunc(connector.connector().userMoneyRank, "", "get", app.tokens, function (res) {
    // console.log(res)
    if (res.statusCode == 200) {
      // console.log(res.data)
      that.setData({
        list:res.data.result
      })
    }else{
      connector.showToasts(res.errMsg)
    }
  }, function (res) {
    connector.showToasts("内部错误")
    // wx.showToast({
    //   title: "内部错误",
    //   icon: 'none',
    //   duration: 1000
    // })
  })
}
//用户提现金额限制
function userMoneyLimit(that){
  connector.getFunc(connector.connector().userMoneyLimit, "", "get", app.tokens, function (res) {
    console.log(res)
    if (res.statusCode == 200) {
      // console.log(res.data)
      that.setData({
        limit:res.data.result.limit
      })
    }else{
      connector.showToasts(res.errMsg)
    }
  }, function (res) {
    connector.showToasts("内部错误")
  })
}
